package redlib.backend.service.utils;

import org.springframework.beans.BeanUtils;
import org.springframework.util.Assert;
import redlib.backend.dto.BioinformaticDocDTO;
import redlib.backend.dto.DepartmentDTO;
import redlib.backend.model.BioinformaticDoc;
import redlib.backend.model.Department;
import redlib.backend.utils.FormatUtils;
import redlib.backend.vo.BioinformaticDocVO;
import redlib.backend.vo.DepartmentVO;

import java.util.Map;

/**
 * @author Zane
 * @description
 */
public class BioinformaticDocUtils {
    /**
     * 规范并校验bioinformaticDocDTO
     *
     * @param bioinformaticDocDTO
     */
    public static void validateBioinformaticDoc(BioinformaticDocDTO bioinformaticDocDTO) {
        FormatUtils.trimFieldToNull(bioinformaticDocDTO);
        Assert.notNull(bioinformaticDocDTO, "文献输入数据不能为空");
        Assert.hasText(bioinformaticDocDTO.getTitle(), "文献名称不能为空");
    }

    /**
     * 将实体对象转换为VO对象
     *
     * @param bioinformaticDoc 实体对象
     * @param nameMap
     * @return VO对象
     */
    public static BioinformaticDocVO convertToVO(BioinformaticDoc bioinformaticDoc, Map<Integer, String> nameMap) {
        BioinformaticDocVO bioinformaticDocVO = new BioinformaticDocVO();
        BeanUtils.copyProperties(bioinformaticDoc, bioinformaticDocVO);

        bioinformaticDocVO.setCreatedByDesc(nameMap.get(bioinformaticDoc.getCreatedBy()));
        return bioinformaticDocVO;
    }
}
